package Practice;

public class Test0013 {
}

class Solution0013_1{
    private class NumMatrix{
        int[][] sum;
        public NumMatrix(int[][] matrix) {
            int length1 = matrix.length;
            int length2 = matrix[0].length;
            this.sum = new int[length1+1][length2+1];
            for (int i = 0; i < length1; i++) {
                int[] temp = matrix[i];
                for (int j = 0; j < length2; j++) {
                    sum[i+1][j+1] = sum[i+1][j]+sum[i][j+1]-sum[i][j]+temp[j];
                }
            }
        }

        public int sumRegion(int row1, int col1, int row2, int col2) {

            return sum[row1+1][col2+1]-sum[row2+1][col1]-sum[row1][col2+1]+sum[row1][col1];
        }
    }

}
